package cn.com.common.config;

import java.util.List;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * 文件上传参数配置类
 *
 * @author wenbin
 * @version V1.0
 * @date 2020年3月18日
 */
@Component
@ConfigurationProperties(prefix = "file")
public class FileUploadProperties {

	private String path;
	private String url;
	private String accessUrl;
	private List<FileRead> read;
	
	
	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;

		// set accessUrl
		if (StringUtils.isEmpty(url)) {
			this.accessUrl = null;
		}
		this.accessUrl = url.substring(url.lastIndexOf("/")) + "/**";
		System.out.println("accessUrl=" + accessUrl);
	}

	public String getAccessUrl() {
		return accessUrl;
	}
	
	public List<FileRead> getRead() {
		return read;
	}

	public void setRead(List<FileRead> read) {
		this.read = read;
	}
	
	/**
     * 分布式存储READ地址
     */
    public static class FileRead {
    	private String pathRead;
    	private String urlRead;
    	private String accessUrlRead;
    	
    	public String getPathRead() {
    		return pathRead;
    	}

    	public void setPathRead(String pathRead) {
    		this.pathRead = pathRead;
    	}

    	public String getUrlRead() {
    		return urlRead;
    	}

    	public void setUrlRead(String urlRead) {
    		this.urlRead = urlRead;

    		// set accessUrl
    		if (StringUtils.isEmpty(urlRead)) {
    			this.accessUrlRead = null;
    		}
    		this.accessUrlRead = urlRead.substring(urlRead.lastIndexOf("/")) + "/**";
    		System.out.println("accessUrlRead=" + accessUrlRead);
    	}

    	public String getAccessUrlRead() {
    		return accessUrlRead;
    	}
    	
    }
	
	
	
}